package com.scs.application.core.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.scs.application.core.dto.ExcelImportField;
import com.scs.application.core.export.ExportParamDto;
import com.scs.application.core.model.ImportResult;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 */
public interface IBaseService<T> extends IService<T> {

    /**
     * 级联保存
     *
     * @param entity
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    default boolean saveCascadeById(T entity) {
        return save(entity);
    }

    /**
     * 级联修改
     *
     * @param entity
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    default boolean updateCascadeById(T entity) {
        return updateById(entity);
    }

    /**
     * 级联删除
     *
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    default boolean removeCascadeById(Serializable id) {
        return this.removeById(id);
    }

    /**
     * 级联批量删除
     *
     * @param idList
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    default boolean removeCascadeBatchByIds(Collection<? extends Serializable> idList) {
        return this.removeByIds(idList);
    }

    /**
     * excel导入
     * @param file
     * @return
     */
    /*@Transactional(rollbackFor = Exception.class)
    default ImportResult excelImport(MultipartFile file){
        throw new UnsupportedOperationException("不支持的操作");
    }

    *//**
     * excel导入
     * @param file
     * @return
     *//*
    @Transactional(rollbackFor = Exception.class)
    default ImportResult excelImport(MultipartFile file, Map<String,Object> params){
        return this.excelImport(file);
    }
*/
    ImportResult excelImport(MultipartFile file);
    ImportResult excelImport(MultipartFile file, Map<String,Object> params);

    /**
     * 批量保存指定实体
     * @param modelClass
     * @param entityList
     * @param batchSize
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    <R> boolean saveBatch(Class<R> modelClass, Collection<R> entityList, int batchSize);


    // 导出数据
    String exportFullData(QueryWrapper queryWrapper, ExportParamDto exportParams, Map<String, Object> userParam, HttpServletRequest request);

    //下载导入模板
    void excelDownloadTemp(HttpServletResponse response, Map<String, String> reqData, List<ExcelImportField> exportHeadListParam);
}

